﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static GylCSharpUtils.GSerializer.Utils.GSerialUtils;

namespace GylCSharpUtils.GSerializer.Utils {
    public class RefInfo {

        public string tag;
        public SerialObjID sourcePtr;
        public SerialObjID targetPtr;

        public RefInfo(string tag, SerialObjID sourcePtr, SerialObjID targetPtr) {
            if(targetPtr == null || sourcePtr == null || tag == null) throw new Exception("必要参数缺失");
            this.tag = tag;
            this.sourcePtr = sourcePtr;
            this.targetPtr = targetPtr;
        }

        public override bool Equals(object obj) {
            if(obj == this) return true;
            if(!(obj is RefInfo)) return false;
            RefInfo other = (RefInfo)obj;
            if(!sourcePtr.Equals(other.sourcePtr)) return false;
            if(!targetPtr.Equals(other.targetPtr)) return false;
            if(!tag.Equals(other.tag)) return false;
            return true;
        }

        public override int GetHashCode() {
            return 1670761668 + sourcePtr.GetHashCode() - targetPtr.GetHashCode();
        }

        public override string ToString() {
            return String.Format($"{sourcePtr.ToString()}.{tag} = {targetPtr.ToString()}");
        }
    }
}
